//
//  BtcTransactionSignParams.m
//  Test
//
//  Created by xgc on 12/26/17.
//  Copyright © 2017 xgc. All rights reserved.
//

#import "BtcTransactionSignParams.h"
#import "CABtcVout.h"

@implementation BtcTransactionSignParams

-(BtcCreateSignTransactionParams*) toBtcCreateSignTransactionParams {
    
    BtcCreateSignTransactionParams* signParams = new BtcCreateSignTransactionParams();
    
    BtSeed* seed = [self.btSeed toBtSeed];
    signParams->setBtSeed(*seed);
    delete seed;
    
    string fromAddress = [self.fromAddress UTF8String];
    signParams->setFromAddress(fromAddress);
    
    string sendAddress = [self.sendAddress UTF8String];
    signParams->setSendAddress(sendAddress);
    
    uint64_t sendValue = self.sendValue;
    signParams->setSendValue(sendValue);
    
    uint64_t feePerKb = self.feePerKb;
    signParams->setFeePerKb(feePerKb);
    
    string password = [self.password UTF8String];
    signParams->setPassword(password);
    
    string priKey = [self.priKey UTF8String];
    signParams->setPriKey(priKey);
    
    vector<BtcvoutForm> btcvoutFormList;
    for(id obj in self.btcvoutFormList) {
        
        CABtcVout* caVout = (CABtcVout*)obj;
        BtcvoutForm* vout = [caVout toBtcvoutForm];
        
        btcvoutFormList.push_back(*vout);
        delete vout;
    }
    
    signParams->setBtcvoutFormList(btcvoutFormList);
    signParams->setRecipientsPayFees(self.recipientsPayFees == YES ? true : false);
	signParams->setTxType((TxType)self.txType);
	
	void *buffer = (void*)[self.data bytes];
    size_t len = [self.data length];
    
    vector<uint8_t> data((uint8_t*)buffer, (uint8_t*)buffer + len);
	signParams->setData(data);
    
    return signParams;
}

-(id)init {
    if (self = [super init]) {
        self.recipientsPayFees = NO;
		self.txType = 0;
    }
    return self;
}

@end
